<?php
/**
* @package RAMLatestjobs
* @version 1.5.1 Stable, May 2009
*/

class mod_RAM_LatestjobsHelper {
//
// get the n latest jobs from  Recruitment Agency Manager
//
function getLatestjobs($no_to_display)    {
	global $msg;

	$jobs = array();

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	$query="select * from ".$dbprefix."RAM_jobs where jobfilled='n' order by id desc limit 0, $no_to_display";
//	$msg = "<p>SQL: $query</p>\n";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// records found?	
	if ($num_rows>0) {
		// yes
		while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
			$jobs[] = $row; // add the job details to the array
		}

	} else { // no, return error message

		$msg = JText::_('RAM_LJM_NOJOBS');

	} // eof check for records found

        return $jobs; // return any jobs found

} // end function getLatestjobs

//
function getArea($area) {

	//get the database configuration settings
	$conf =& JFactory::getConfig();
	$dbhost = $conf->getValue('config.host');
	$dbuser = $conf->getValue('config.user');
	$dbpassword = $conf->getValue('config.password');
	$dbname = $conf->getValue('config.db');
	$dbprefix = $conf->getValue('config.dbprefix');

	// connect to the database
	mysql_connect($dbhost,$dbuser,$dbpassword) or die("mysql_connect fail");
	mysql_select_db($dbname) or die("mysql_select_db fail");

	// get area details
	$query="select * from ".$dbprefix."RAM_Areas where id = '$area' ";
	$sth=mysql_query($query);
	$num_rows = mysql_num_rows($sth);
	// area found?
	if ($num_rows>0) {
		$row=mysql_fetch_array($sth, MYSQL_ASSOC);
		$Country=$row['Country'];
		$County=$row['County'];
		return "$Country, $County";
	} else {
		return JText::_('RAM_LJM_LOCNOTFOUND');
	} // eof check for area found

} // end function getArea


} // eof class

?>
